using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models;
using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Attributes;
using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Attributes.DomainAttributes;
using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Enums;
using System.Collections.Generic;
using System.ComponentModel;

namespace Baci.ArcGIS._SpaceTimePatternMiningTools._TimeSeriesForecasting
{
    /// <summary>
    /// <para>Forest-based Forecast</para>
    /// <para>Forecasts the values of each location of a space-time cube using an adaptation of Leo Breiman's random forest algorithm. The forest regression model is trained using time windows on each location of the space-time cube.</para>
    /// <para>使用 Leo Breiman 的随机森林算法的改编来预测时空立方体每个位置的值。森林回归模型使用时空立方体每个位置的时间窗口进行训练。</para>
    /// </summary>    
    [DisplayName("Forest-based Forecast")]
    public class ForestBasedForecast : AbstractGPProcess
    {
        /// <summary>
        /// 无参构造
        /// </summary>
        public ForestBasedForecast()
        {

        }

        /// <summary>
        /// 有参构造
        /// </summary>
        /// <param name="_in_cube">
        /// <para>Input Space Time Cube</para>
        /// <para>The netCDF cube containing the variable to forecast to future time steps. This file must have an .nc file extension and must have been created using the Create Space Time Cube By Aggregating Points, Create Space Time Cube From Defined Locations, or Create Space Time Cube From Multidimensional Raster Layer tool.</para>
        /// <para>包含要预测到未来时间步长的变量的 netCDF 多维数据集。此文件必须具有 .nc 文件扩展名，并且必须已使用通过聚合点创建时空立方体、从定义位置创建时空立方体或从多维栅格图层创建时空立方体工具创建。</para>
        /// </param>
        /// <param name="_analysis_variable">
        /// <para>Analysis Variable</para>
        /// <para>The numeric variable in the netCDF file that will be forecasted to future time steps.</para>
        /// <para>netCDF 文件中将预测到未来时间步长的数值变量。</para>
        /// </param>
        /// <param name="_output_features">
        /// <para>Output Features</para>
        /// <para>The output feature class of all locations in the space-time cube with forecasted values stored as fields. The layer displays the forecast for the final time step and contains pop-up charts showing the time series, forecasts, and 90 percent confidence bounds for each location.</para>
        /// <para>时空立方体中所有位置的输出要素类，其预测值存储为字段。该图层显示最终时间步长的预测，并包含显示每个位置的时间序列、预测和 90% 置信度边界的弹出式图表。</para>
        /// </param>
        public ForestBasedForecast(object _in_cube, object _analysis_variable, object _output_features)
        {
            this._in_cube = _in_cube;
            this._analysis_variable = _analysis_variable;
            this._output_features = _output_features;
        }
        public override string ToolboxName => "Space Time Pattern Mining Tools";

        public override string ToolName => "Forest-based Forecast";

        public override string CallName => "stpm.ForestBasedForecast";

        public override List<string> AcceptEnvironments => ["outputCoordinateSystem", "parallelProcessingFactor", "randomGenerator"];

        public override object[] ParameterInfo => [_in_cube, _analysis_variable, _output_features, _output_cube, _number_of_time_steps_to_forecast, _time_window, _number_for_validation, _number_of_trees, _minimum_leaf_size, _maximum_depth, _sample_size, _forecast_approach.GetGPValue(), _outlier_option.GetGPValue(), _level_of_confidence.GetGPValue(), _maximum_number_of_outliers];

        /// <summary>
        /// <para>Input Space Time Cube</para>
        /// <para>The netCDF cube containing the variable to forecast to future time steps. This file must have an .nc file extension and must have been created using the Create Space Time Cube By Aggregating Points, Create Space Time Cube From Defined Locations, or Create Space Time Cube From Multidimensional Raster Layer tool.</para>
        /// <para>包含要预测到未来时间步长的变量的 netCDF 多维数据集。此文件必须具有 .nc 文件扩展名，并且必须已使用通过聚合点创建时空立方体、从定义位置创建时空立方体或从多维栅格图层创建时空立方体工具创建。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Input Space Time Cube")]
        [Description("")]
        [Option(OptionTypeEnum.Must)]
        public object _in_cube { get; set; }


        /// <summary>
        /// <para>Analysis Variable</para>
        /// <para>The numeric variable in the netCDF file that will be forecasted to future time steps.</para>
        /// <para>netCDF 文件中将预测到未来时间步长的数值变量。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Analysis Variable")]
        [Description("")]
        [Option(OptionTypeEnum.Must)]
        public object _analysis_variable { get; set; }


        /// <summary>
        /// <para>Output Features</para>
        /// <para>The output feature class of all locations in the space-time cube with forecasted values stored as fields. The layer displays the forecast for the final time step and contains pop-up charts showing the time series, forecasts, and 90 percent confidence bounds for each location.</para>
        /// <para>时空立方体中所有位置的输出要素类，其预测值存储为字段。该图层显示最终时间步长的预测，并包含显示每个位置的时间序列、预测和 90% 置信度边界的弹出式图表。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Output Features")]
        [Description("")]
        [Option(OptionTypeEnum.Must)]
        public object _output_features { get; set; }


        /// <summary>
        /// <para>Output Space Time Cube</para>
        /// <para>A new space-time cube (.nc file) containing the values of the input space-time cube with the forecasted time steps appended. The Visualize Space Time Cube in 3D tool can be used to see all of the observed and forecasted values simultaneously.</para>
        /// <para>一个新的时空立方体（.nc 文件），其中包含附加了预测时间步长的输入时空立方体的值。可视化 3D 时空立方体工具可用于同时查看所有观测值和预测值。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Output Space Time Cube")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public object _output_cube { get; set; } = null;


        /// <summary>
        /// <para>Number of Time Steps to Forecast</para>
        /// <para>A positive integer specifying the number of time steps to forecast. This value cannot be larger than 50 percent of the total time steps in the input space-time cube. The default value is one time step.</para>
        /// <para>一个正整数，指定要预测的时间步长数。此值不能大于输入时空立方体中总时间步长的 50%。默认值为一个时间步长。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Number of Time Steps to Forecast")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long _number_of_time_steps_to_forecast { get; set; } = 1;


        /// <summary>
        /// <para>Time Step Window</para>
        /// <para>The number of previous time steps to use when training the model. If your data displays seasonality (repeating cycles), provide the number of time steps corresponding to one season. This value cannot be larger than one-third of the number of time steps in the input space-time cube. If no value is provided, a time window is estimated for each location using a spectral density function.</para>
        /// <para>训练模型时要使用的先前时间步长数。如果数据显示季节性（重复周期），请提供与一个季节对应的时间步长数。此值不能大于输入时空立方体中时间步长数的三分之一。如果未提供任何值，则使用光谱密度函数估计每个位置的时间窗口。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Time Step Window")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long? _time_window { get; set; } = null;


        /// <summary>
        /// <para>Number of Time Steps to Exclude for Validation</para>
        /// <para>The number of time steps at the end of each time series to exclude for validation. The default value is 10 percent (rounded down) of the number of input time steps, and this value cannot be larger than 25 percent of the number of time steps. Provide the value 0 to not exclude any time steps.</para>
        /// <para>每个时间序列末尾要排除以进行验证的时间步数。默认值为输入时间步数的 10%（向下舍入），此值不能大于时间步长数的 25%。提供值 0 以不排除任何时间步长。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Number of Time Steps to Exclude for Validation")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long? _number_for_validation { get; set; } = null;


        /// <summary>
        /// <para>Number of Trees</para>
        /// <para>The number of trees to create in the forest model. More trees will generally result in more accurate model prediction, but the model will take longer to calculate. The default number of trees is 100, and the value must be at least 1 and not greater than 1,000.</para>
        /// <para>要在森林模型中创建的树数。更多的树通常会导致更准确的模型预测，但模型需要更长的时间来计算。默认树数为 100，值必须至少为 1 且不大于 1,000。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Number of Trees")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long _number_of_trees { get; set; } = 100;


        /// <summary>
        /// <para>Minimum Leaf Size</para>
        /// <para>The minimum number of observations that are required to keep a leaf (the terminal node on a tree without further splits). For very large data, increasing this number will decrease the run time of the tool.</para>
        /// <para>保留叶（树上的终端节点，无需进一步拆分）所需的最小观测值数。对于非常大的数据，增加此数字将减少工具的运行时间。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Minimum Leaf Size")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long? _minimum_leaf_size { get; set; } = null;


        /// <summary>
        /// <para>Maximum Tree Depth</para>
        /// <para>The maximum number of splits that will be made down a tree. Using a large maximum depth, more splits will be created, which may increase the chances of overfitting the model. If no value is provided, a value will be identified by the tool based on the number of trees created by the model and the size of the time step window.</para>
        /// <para>将沿着树进行的最大拆分数。使用较大的最大深度，将创建更多的分割，这可能会增加模型过度拟合的机会。如果未提供任何值，则工具将根据模型创建的树数和时间步长窗口的大小来识别值。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Maximum Tree Depth")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long? _maximum_depth { get; set; } = null;


        /// <summary>
        /// <para>Percentage of Training Available per Tree</para>
        /// <para>The percent of training data that will be used to fit the forecast model. The training data consists of associated explanatory and dependent variables constructed using time windows. All remaining training data will be used to optimize the parameters of the forecast model. The default is 100 percent.</para>
        /// <para>将用于拟合预测模型的训练数据的百分比。训练数据由使用时间窗口构建的相关解释变量和因变量组成。所有剩余的训练数据将用于优化预测模型的参数。默认值为 100%。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Percentage of Training Available per Tree")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long _sample_size { get; set; } = 100;


        /// <summary>
        /// <para>Forecast Approach</para>
        /// <para><xdoc>
        ///   <para>Specifies how the explanatory and dependent variables will be represented when training the forest model at each location.</para>
        ///   <para>To train the forest model that will be used to forecast, sets of explanatory and dependent variables must be created using time windows. Use this parameter to specify whether these variables will be linearly detrended and whether the dependent variable will be represented by its raw value or by the residual of a linear regression model. This linear regression model uses all time steps within a time window as explanatory variables and uses the following time step as the dependent variable. The residual is calculated by subtracting the predicted value based on linear regression from the raw value of the dependent variable.</para>
        ///   <bulletList>
        ///     <bullet_item>Build model by value— Values within the time window will not be detrended and the dependent variable will be represented by its raw value.</bullet_item><para/>
        ///     <bullet_item>Build model by value after detrending— Values within the time window will be linearly detrended, and the dependent variable will be represented by its detrended value. This is the default.</bullet_item><para/>
        ///     <bullet_item>Build model by residual— Values within the time window will not be detrended, and the dependent variable will be represented by the residual of a linear regression model using the values within the time window as explanatory variables.</bullet_item><para/>
        ///     <bullet_item>Build model by residual after detrending— Values within the time window will be linearly detrended, and the dependent variable will be represented by the residual of a linear regression model using the detrended values within the time window as explanatory variables.</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>指定在每个位置训练林模型时如何表示解释变量和因变量。</para>
        ///   <para>若要训练将用于预测的森林模型，必须使用时间窗创建解释变量和因变量集。使用此参数可以指定这些变量是否将线性去趋势化，以及因变量是用其原始值还是由线性回归模型的残差表示。此线性回归模型使用时间窗口内的所有时间步长作为解释变量，并使用以下时间步长作为因变量。残差的计算方法是从因变量的原始值中减去基于线性回归的预测值。</para>
        ///   <bulletList>
        ///     <bullet_item>按值构建模型 - 时间窗口内的值不会去趋势化，因变量将由其原始值表示。</bullet_item><para/>
        ///     <bullet_item>去趋势后按值构建模型 - 时间窗口内的值将线性去趋势，因变量将由其去趋势值表示。这是默认设置。</bullet_item><para/>
        ///     <bullet_item>通过残差构建模型 - 时间窗内的值不会去趋势化，因变量将由线性回归模型的残差表示，使用时间窗内的值作为解释变量。</bullet_item><para/>
        ///     <bullet_item>去趋势后通过残差构建模型 - 时间窗内的值将线性去趋势化，因变量将由线性回归模型的残差表示，使用时间窗内的去趋势值作为解释变量。</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Forecast Approach")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public _forecast_approach_value _forecast_approach { get; set; } = _forecast_approach_value._VALUE_DETREND;

        public enum _forecast_approach_value
        {
            /// <summary>
            /// <para>Build model by value</para>
            /// <para>Build model by value— Values within the time window will not be detrended and the dependent variable will be represented by its raw value.</para>
            /// <para>按值构建模型 - 时间窗口内的值不会去趋势化，因变量将由其原始值表示。</para>
            /// </summary>
            [Description("Build model by value")]
            [GPEnumValue("VALUE")]
            _VALUE,

            /// <summary>
            /// <para>Build model by value after detrending</para>
            /// <para>Build model by value after detrending— Values within the time window will be linearly detrended, and the dependent variable will be represented by its detrended value. This is the default.</para>
            /// <para>去趋势后按值构建模型 - 时间窗口内的值将线性去趋势，因变量将由其去趋势值表示。这是默认设置。</para>
            /// </summary>
            [Description("Build model by value after detrending")]
            [GPEnumValue("VALUE_DETREND")]
            _VALUE_DETREND,

            /// <summary>
            /// <para>Build model by residual</para>
            /// <para>Build model by residual— Values within the time window will not be detrended, and the dependent variable will be represented by the residual of a linear regression model using the values within the time window as explanatory variables.</para>
            /// <para>通过残差构建模型 - 时间窗内的值不会去趋势化，因变量将由线性回归模型的残差表示，使用时间窗内的值作为解释变量。</para>
            /// </summary>
            [Description("Build model by residual")]
            [GPEnumValue("RESIDUAL")]
            _RESIDUAL,

            /// <summary>
            /// <para>Build model by residual after detrending</para>
            /// <para>Build model by residual after detrending— Values within the time window will be linearly detrended, and the dependent variable will be represented by the residual of a linear regression model using the detrended values within the time window as explanatory variables.</para>
            /// <para>去趋势后通过残差构建模型 - 时间窗内的值将线性去趋势化，因变量将由线性回归模型的残差表示，使用时间窗内的去趋势值作为解释变量。</para>
            /// </summary>
            [Description("Build model by residual after detrending")]
            [GPEnumValue("RESIDUAL_DETREND")]
            _RESIDUAL_DETREND,

        }

        /// <summary>
        /// <para>Outlier Option</para>
        /// <para><xdoc>
        ///   <para>Specifies whether statistically significant time series outliers will be identified.</para>
        ///   <bulletList>
        ///     <bullet_item>None—Outliers will not be identified. This is the default.</bullet_item><para/>
        ///     <bullet_item>Identify outliers—Outliers will be identified using the Generalized ESD test.</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>指定是否识别具有统计显著性的时间序列异常值。</para>
        ///   <bulletList>
        ///     <bullet_item>无—不会识别异常值。这是默认设置。</bullet_item><para/>
        ///     <bullet_item>识别异常值—将使用广义 ESD 检验识别异常值。</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Outlier Option")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public _outlier_option_value _outlier_option { get; set; } = _outlier_option_value._NONE;

        public enum _outlier_option_value
        {
            /// <summary>
            /// <para>None</para>
            /// <para>None—Outliers will not be identified. This is the default.</para>
            /// <para>无—不会识别异常值。这是默认设置。</para>
            /// </summary>
            [Description("None")]
            [GPEnumValue("NONE")]
            _NONE,

            /// <summary>
            /// <para>Identify outliers</para>
            /// <para>Identify outliers—Outliers will be identified using the Generalized ESD test.</para>
            /// <para>识别异常值—将使用广义 ESD 检验识别异常值。</para>
            /// </summary>
            [Description("Identify outliers")]
            [GPEnumValue("IDENTIFY")]
            _IDENTIFY,

        }

        /// <summary>
        /// <para>Level of Confidence</para>
        /// <para><xdoc>
        ///   <para>Specifies the confidence level for the test for time series outliers.</para>
        ///   <bulletList>
        ///     <bullet_item>90%—The confidence level for the test is 90 percent. This is the default.</bullet_item><para/>
        ///     <bullet_item>95%—The confidence level for the test is 95 percent.</bullet_item><para/>
        ///     <bullet_item>99%—The confidence level for the test is 99 percent.</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>指定时间序列异常值检验的置信度。</para>
        ///   <bulletList>
        ///     <bullet_item>90%—检验的置信度为 90%。这是默认设置。</bullet_item><para/>
        ///     <bullet_item>95%—检验的置信水平为 95%。</bullet_item><para/>
        ///     <bullet_item>99%—检验的置信水平为 99%。</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Level of Confidence")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public _level_of_confidence_value _level_of_confidence { get; set; } = _level_of_confidence_value.value0;

        public enum _level_of_confidence_value
        {
            /// <summary>
            /// <para>90%</para>
            /// <para>90%—The confidence level for the test is 90 percent. This is the default.</para>
            /// <para>90%—检验的置信度为 90%。这是默认设置。</para>
            /// </summary>
            [Description("90%")]
            [GPEnumValue("90%")]
            value0,

            /// <summary>
            /// <para>95%</para>
            /// <para>95%—The confidence level for the test is 95 percent.</para>
            /// <para>95%—检验的置信水平为 95%。</para>
            /// </summary>
            [Description("95%")]
            [GPEnumValue("95%")]
            value1,

            /// <summary>
            /// <para>99%</para>
            /// <para>99%—The confidence level for the test is 99 percent.</para>
            /// <para>99%—检验的置信水平为 99%。</para>
            /// </summary>
            [Description("99%")]
            [GPEnumValue("99%")]
            value2,

        }

        /// <summary>
        /// <para>Maximum Number of Outliers</para>
        /// <para>The maximum number of time steps that can be declared outliers for each location. The default value corresponds to 5 percent (rounded down) of the number of time steps of the input space-time cube (a value of at least 1 will always be used). This value cannot exceed 20 percent of the number of time steps.</para>
        /// <para>每个位置可以声明为异常值的最大时间步数。默认值对应于输入时空立方体的时间步长数的 5%（向下舍入）（将始终使用至少 1 的值）。此值不能超过时间步长数的 20%。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Maximum Number of Outliers")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long? _maximum_number_of_outliers { get; set; } = null;


        public ForestBasedForecast SetEnv(object outputCoordinateSystem = null, object parallelProcessingFactor = null, object randomGenerator = null)
        {
            base.SetEnv(outputCoordinateSystem: outputCoordinateSystem, parallelProcessingFactor: parallelProcessingFactor, randomGenerator: randomGenerator);
            return this;
        }

    }

}